package com.gzwanchuang.xhgj.ui.page.glide;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.gzwanchuang.xhgj.R;
import com.gzwanchuang.xhgj.help.PreferenceSettings;
import com.gzwanchuang.xhgj.ui.LoginActivity;
import com.gzwanchuang.xhgj.ui.base.BaseFragment;

import cn.bingoogolapple.bgabanner.BGABanner;
import cn.bingoogolapple.bgabanner.BGALocalImageSize;

/**
 * 文件名 : HomeRootFragment
 * 创建者 : MangoWang
 * 创建日期 : 2019/12/24 16:20
 * 微信 : MangoWaWang
 * 邮箱 : 763482205@qq.com
 * 描述 : TODO
 */
public class GlideFragment extends BaseFragment {


    private BGABanner mBackgroundBanner;
    private String IS_FIRST = "is_have_welcome";

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_glide, container, false);
        mBackgroundBanner = view.findViewById(R.id.banner_guide_background);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        setListener();
        processLogic();

    }

    /**
     * 设置进入按钮和跳过按钮控件资源 id 及其点击事件
     * 如果进入按钮和跳过按钮有一个不存在的话就传 0
     * 在 BGABanner 里已经帮开发者处理了防止重复点击事件
     * 在 BGABanner 里已经帮开发者处理了「跳过按钮」和「进入按钮」的显示与隐藏
     */
    private void setListener() {
        mBackgroundBanner.setEnterSkipViewIdAndDelegate(R.id.btn_guide_enter, R.id.tv_guide_skip, () -> {
            // 显示状态栏
            startActivity(new Intent(getContext(), LoginActivity.class));
            PreferenceSettings.setWelcome(false);
            mActivity.finish();
        });
    }

    private void processLogic() {
        mBackgroundBanner.setBackgroundResource(android.R.color.white);
        // Bitmap 的宽高在 maxWidth maxHeight 和 minWidth minHeight 之间
        BGALocalImageSize localImageSize = new BGALocalImageSize(3000, 3000, 320f, 640f);
        // 设置数据源
        mBackgroundBanner.setData(
                localImageSize, ImageView.ScaleType.CENTER_CROP,
                R.mipmap.guide_background_1,
                R.mipmap.guide_background_2
        );
    }
}
